package com.hnl.action.talent;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.Vector;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hnl.core.aware.HNLAuthAware;
import com.hnl.dao.DAOException;
import com.hnl.dao.HNLDAOFactory;
import com.hnl.dao.TalentDAO;
import com.hnl.to.Talent;
import com.hnl.to.User;
import com.hnl.to.wrapper.TalentWrapper;
import com.hnl.util.JSONResponseUtil;

@SuppressWarnings("serial")
@Deprecated
public class LoadAllTalentForLoginUser extends HttpServlet implements
		HNLAuthAware {
	public static final Logger LOG = LoggerFactory
			.getLogger(LoadAllTalentForLoginUser.class);

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		PrintWriter writer = resp.getWriter();
		try {
			HttpSession session = ((HttpServletRequest) req).getSession();
			User user = (User) session.getAttribute(ATTRIBUTE_USER);

			TalentDAO talentDAO = HNLDAOFactory.getDAOFactory(
					HNLDAOFactory.HNLDAOFACTORY).getTalentDAO();
			Collection<Talent> talentColletion = talentDAO
					.loadTalentByUserId(user.getUserID());

			Collection<TalentWrapper> talentWrapperColletion = new Vector<TalentWrapper>();

			for (Talent talent : talentColletion) {
				TalentWrapper newTalentWrapper = new TalentWrapper(talent);
				newTalentWrapper.getGUIExpertise();
				newTalentWrapper.getIndustry1Text();
				newTalentWrapper.getModifiedUserIDText();
				talentWrapperColletion.add(newTalentWrapper);
			}
			
			writer.println(JSONResponseUtil
					.getJSONObjectString(talentWrapperColletion));
		} catch (DAOException e) {
			LOG.error("error laoding Talent", e);
		} finally{
			writer.close();
		}

	}
}
